package com.javastudy;

import java.io.StreamCorruptedException;
import java.util.Scanner;

import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import org.junit.Test;

public class Test_homework {
//	1、int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//	求出上面数组中0-9分别出现的次数
	@Test 
	public void Test01(){
		int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int count = 0;
		for (int i = 0; i < 9; i++) {
			for (int j = 0; j < score.length; j++) {
				if (i == score[j]) {
					count++;
				}
			}
			System.out.println(i+"出现的次数为："+count);
			count = 0;
		}
	}
	//这种做法的事件O（）= 10*30=300，显然这种方式造成了时间和资源上的浪费。
	//for结构的层次越，造成这种时间及资源上的浪费就越严重。
//	2、int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//	要求求出其中的奇数个数和偶数个数。		
	@Test
	public void Test02(){
		int[] score={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int oddcount = 0,evecount = 0;
		for (int i = 0; i < score.length; i++) {
			if (score[i] % 2 == 0){
				evecount++;
			}else {
				oddcount++;
			}
		}
		System.out.println("奇数的个数是："+oddcount);
		System.out.println("偶数的个数为："+evecount);
	}
//	3、输入一组学生的成绩，然后计算他们的平均值.
	@Test
	public void Test03(){
		Scanner input = new Scanner(System.in);
		System.out.println("请输入学生个人数：");
		int num = input.nextInt();
		int avg = 0,all =0;
		int[] score = new int[num];
		System.out.println("请依次输入学生成绩：");
		for (int i = 0; i < score.length; i++) {
			score[i] = input.nextInt();
		}
		for (int i = 0; i < score.length; i++) {
			all += score[i];
		}
		avg = all/num;
		System.out.println("学生的平均成绩是："+avg);
	}
	
	
//5-10:BDACAC 11-15:BBCBA
	
//	16、题目：一个5位数，判断它是不是回文数。即12321是回文数，个位与万位相同，十位与千位相同。	
	@Test
	public void Test04(){
		System.out.println("请输入需要判断的数字：");
		Scanner input = new Scanner(System.in);
		int backword = input.nextInt();
		if (backword/10000 == backword%10 && (backword/1000)%10 == (backword%100)/10) {
			System.out.println(backword+"是回文。");
		}else {
			System.out.println(backword+"不是回文");
		}
	}
//	17、输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。	
	@Test
	public void Test05(){
		System.out.println("请输入字符串：");
		Scanner input = new Scanner(System.in);
		String str  = input.nextLine();
		char[] x = str.toCharArray();
		int count_Eng = 0,count_num = 0,count_other = 0,count_space = 0;
		for (int i = 0; i < x.length; i++) {
			if (Character.isDigit(x[i])) {
				count_num++;
			}else if (Character.isLetter(x[i])) {
				count_Eng++;
			}else if (Character.isSpace(x[i])) {
				count_space++;
			}else {
				count_other++;
			}
		}
        System.out.println("数字的个数是"+count_num);  
        System.out.println("字符的个数是"+count_Eng);  
        System.out.println("空值的个数是"+count_space);  
        System.out.println("其他的个数是"+count_other);
	}
//	18、题目：输入三个整数x,y,z，请把这三个数由小到大输出。

	@Test
	public void Test06(){
		System.out.println("请输入三个整数：");
		Scanner input = new Scanner(System.in);
		int x = input.nextInt();
		int y = input.nextInt();
		int z = input.nextInt();
		int temp = 0;
		if (x > y) {
			temp = x;
			x = y;
			y = temp;
			if (z < y && z < x){
				temp = z;
				z = y;
				y = temp;
				temp = x;
				x = y;
				y = temp;
				System.out.println(x+" "+y+" "+z);
			}else {
				temp = z;
				z = y;
				y = temp;
				System.out.println(x+" "+y+" "+z);
			}
		}else if (x < y) {
			if (z < y && z < x) {
				temp = z;
				z = y;
				y = temp;
				temp = x;
				x = y;
				y = temp;
				System.out.println(x+" "+y+" "+z);
			}else if(z <y && z > x){
				temp = y;
				y = z;
				z = temp;
				System.out.println(x+" "+y+" "+z);
			}else {
				System.out.println(x+" "+y+" "+z);
			}
		}
		
	}
	@Test
	public void Test07(){
		for(int i=0;i<3;i++){
			switch(i){
			case 1:
			System.out.println("a");
			break;
			case 0:
			System.out.println("b");
			break;
			default:
			System.out.println("c");
			case 2:
			System.out.println("d");
			}
			}

	}
	@Test
	public void paste() {
		for (int i = 1; i < 6; i++) {
			for (int j = 1; j <= 6-i; j++) {
				System.out.print("*");
			}
			System.out.println("");
		}
	}
//	2，	编写一个方法求s=a+aa+aaa+a...a，其中a是一个数，
//		比如a=2；那么求s=2+22+222+2222...的值。
//		该方法需要两个参数，第一个参数控制a，第二个参数控制有多少个数。
	@Test
	public void Test08(){
		Scanner input = new Scanner(System.in);
		System.out.println("请输入a的值及a的个数：");
		int a = input.nextInt();
		int num = input.nextInt();
		int s = 0,y = 0;
		//s = a*1+a*11+a*111+....+a*(num个1)
		for (int i = 0; i < num; i++) {
			 y += a*((int)Math.pow(10, i));
			 s += y;
		}
		System.out.println(s);
	}
//	3，给出一组学生的成绩
//	int[] score={80,45,60,100,89,92,93,...}
//	请求出这组成绩中，100分，90-99，80-89的学生人数。
	@Test
	public void Test09(){
		Scanner input = new Scanner(System.in);
		System.out.println("请输入学生人数");
		int num = input.nextInt();
		System.out.println("请依次输入学生成绩：");
		int[] score = new int[num];
		int count_100 = 0,count_9 = 0,count_8 = 0;
		for (int i = 0; i < score.length; i++) {
			score[i] = input.nextInt();
		}
		for (int i = 0; i < score.length; i++) {
			if (score[i] == 100) {
				count_100++;
			}else if (score[i]/10 == 9) {
				count_9++;
			}else if (score[i]/10 == 8) {
				count_8++;
			}else {
			}

		}
		System.out.println("100分的人数是："+count_100);
		System.out.println("90-99分的人数是："+count_9);
		System.out.println("80-89分的人数是："+count_8);
			
	}
}
